/**
 *获取本地存储的信息
 */
export function getStorageSync(key) {
	try {
		const obj = uni.getStorageSync(key)
		if (obj) {
			return obj
		}
		return false
	} catch (e) {
		return false
	}
}

/**
 *设置本地存储
 */
export function setStorageSync(key, value) {
	try {
		uni.setStorageSync(key, value)
	} catch (e) {
		return false
	}
}

/**
 *移除本地存储
 */
export function removeStorageSync(key) {
	try {
		uni.removeStorageSync(key)
	} catch (e) {
		console.log(e);
	}
}

/**
 * 睡眠函数
 */
export function sleep(time) {
	return new Promise(resolve => setTimeout(resolve, time))
}
/**
 * 不足两位前面补0
 * */
export function formatNumber(n = 0) {
	n = n.toString()
	return n[1] ? n : '0' + n
}

/**
 * 根据参数构建URL；
 */
export function buildUrl(uri, params) {
  let tmpParams = [];

  Object.keys(params).forEach((key) => {

    let value = params[key]
    if (typeof value === 'undefined' || value === null) {
      value = '';
    }
    tmpParams.push([key, value].join('='));
  });
  let str = ''
  if (tmpParams && tmpParams[0]) {
    str = '?' + tmpParams.join('&')
  }
  return uri + str
}

